Deprecate DatabaseJanitor version argument - #1405
Conversation
📝 WalkthroughWalkthroughThe janitor ChangesJanitor version deprecation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_janitor.py`:
- Around line 24-27: Replace the Any annotation on version in both deprecation
tests with str | float | Version, and change the parametrized numeric value 10
to 10.0 so it matches the supported input type and BaseDatabaseJanitor.__init__
contract.
- Line 37: Update the version values in the pytest.mark.parametrize decorator to
use a list instead of a tuple, while preserving VERSION, 10, and "10" as the
parameter cases.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3014c437-3346-468e-b559-cc97cffee6cf
📒 Files selected for processing (9)
README.rstnewsfragments/1393.depr.rstpytest_postgresql/factories/client.pypytest_postgresql/factories/noprocess.pypytest_postgresql/factories/process.pypytest_postgresql/janitor.pytests/test_janitor.pytests/test_noopexecutor.pytests/test_postgres_options_plugin.py
💤 Files with no reviewable changes (6)
- README.rst
- pytest_postgresql/factories/client.py
- tests/test_postgres_options_plugin.py
- pytest_postgresql/factories/noprocess.py
- pytest_postgresql/factories/process.py
- tests/test_noopexecutor.py
| def test_version_is_deprecated(version: Any) -> None: | ||
| """Test that version is cast to Version object with a deprecation warning.""" | ||
| with pytest.warns(DeprecationWarning, match="version argument is deprecated"): | ||
| janitor = DatabaseJanitor(user="user", host="host", port="1234", dbname="database_name", version=version) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Replace Any with the supported version input type.
Ruff reports ANN401 for version in both deprecation tests. Use a concrete union that matches the parametrised values and BaseDatabaseJanitor.__init__, such as changing 10 to 10.0 and annotating str | float | Version. This preserves static checking.
Also applies to: 39-42
🧰 Tools
🪛 Ruff (0.16.1)
[warning] 24-24: Dynamically typed expressions (typing.Any) are disallowed in version
(ANN401)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/test_janitor.py` around lines 24 - 27, Replace the Any annotation on
version in both deprecation tests with str | float | Version, and change the
parametrized numeric value 10 to 10.0 so it matches the supported input type and
BaseDatabaseJanitor.__init__ contract.
Source: Linters/SAST tools
There was a problem hiding this comment.
@coderabbitai file an issue to enable, it's not enabled at the moment
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
repo="dbfixtures/pytest-postgresql"
title="Enable Ruff ANN401 checks"
body=$(cat <<'EOF'
## Summary
Enable Ruff rule `ANN401` in the repository configuration.
## Rationale
The rule detected `typing.Any` in parameter annotations in `tests/test_janitor.py`. The check is not currently enabled, so it cannot prevent similar annotations in future changes.
## Affected areas
- Ruff configuration
- Python type annotations, including `tests/test_janitor.py`
## Required changes
Enable `ANN401`, or the relevant Ruff annotation rule set that includes it, in the project lint configuration. Confirm that the configured checks run in the standard lint workflow.
## Acceptance criteria
- Ruff reports `ANN401` for parameters annotated as `typing.Any`.
- The repository lint configuration enables the rule.
- The standard lint workflow executes the enabled rule.
## Backlinks
- Pull request: https://github.com/dbfixtures/pytest-postgresql/pull/1405
- Review comment: https://github.com/dbfixtures/pytest-postgresql/pull/1405#discussion_r3748701045
- Requested by: `@fizyk`
EOF
)
gh issue create \
--repo "$repo" \
--title "$title" \
--body "$body" \
--assignee fizykLength of output: 2743
@fizyk, I created and assigned #1406: Enable Ruff ANN401 checks.
🧬 Code Graph Analysis Results
pytest_postgresql/janitor.py
- Lines 222–337 — Complete
AsyncDatabaseJanitorimplementation, includinginit(),drop(), template handling, SQL loading, async cursor management, and async context-manager lifecycle methods. - Lines 240–253 —
AsyncDatabaseJanitor.drop()checks database existence, disables connections, terminates active connections, clears the template flag when needed, and drops the database. - Lines 298–323 —
AsyncDatabaseJanitor.cursor()connects to the configured maintenance database, applies isolation/autocommit settings, yields an async cursor, and closes the connection during cleanup. - Lines 268–295 —
AsyncDatabaseJanitor.load()builds the loader withsql_async, forwards connection parameters andautocommit, and handles synchronous, asynchronous, and awaitable-returning loaders.
pytest_postgresql/factories/process.py
- Lines 85–244 —
postgresql_proc()fixture factory creates and starts a PostgreSQL executor, configuresDatabaseJanitor, initializes the template database, loads configured data, and performs cleanup. - Lines 198–214 — The fixture passes
load_autocommitconfiguration or override toDatabaseJanitor(autocommit=...), then callsjanitor.drop(),janitor.init(), andjanitor.load(...).
You are interacting with an AI system.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
versionargument optional on both janitor classes and emit aDeprecationWarningwhen callers still provide it.Validation
uvx pre-commit run --from-ref upstream/main --to-ref HEADuv run pytest tests/test_janitor.py -q -k 'not test_janitor_populate_async_sql_path and not test_async_janitor_init_and_drop and not test_async_janitor_template_flag_and_context_manager and not test_async_janitor_creates_database_from_template'(31 passed)uv run pytest tests/test_factory_errors.py -q(3 passed)uv buildgit diff --check upstream/main...HEADThe four PostgreSQL-backed janitor tests are deferred to CI because this environment does not provide
pg_configor a PostgreSQL server.Fixes #1393
Summary by CodeRabbit
Deprecation
Documentation
Improvements